﻿#include "string_tool.h"

#ifdef _WIN32
#include <codecvt>
#include <locale>

std::string as::tools::UTF8ToANSI(const std::string &utf8Str)
{
	// 使用UTF-8到宽字符串（Unicode）的转换
	std::wstring_convert<std::codecvt_utf8<wchar_t>> utf8Converter;
	std::wstring utf16Str = utf8Converter.from_bytes(utf8Str);

	// 使用ANSI到宽字符串（Unicode）的转换
	std::wstring_convert<std::codecvt<wchar_t, char, std::mbstate_t>> ansiConverter;
	return ansiConverter.to_bytes(utf16Str);
}

std::wstring as::tools::UTF8ToWString(const std::string &utf8Str)
{
	std::wstring_convert<std::codecvt_utf8<wchar_t>> converter;
	return converter.from_bytes(utf8Str);
}

std::string as::tools::WStringToUTF8(const std::wstring &wStr)
{
	std::wstring_convert<std::codecvt_utf8<wchar_t>> converter;
	return converter.to_bytes(wStr);
}

std::wstring as::tools::ANSIToWString(const std::string &ansiStr)
{
	std::wstring_convert<std::codecvt<wchar_t, char, std::mbstate_t>> converter;
	return converter.from_bytes(ansiStr);
}

std::string as::tools::WStringToANSI(const std::wstring &wStr)
{
	std::wstring_convert<std::codecvt<wchar_t, char, std::mbstate_t>> converter;
	return converter.to_bytes(wStr);
}

#endif